package com.spark.sniffer.plugin.plugins.define.trace;

import com.spark.sniffer.plugin.interceptor.InstanceMethodsInterceptPoint;
import com.spark.sniffer.plugin.interceptor.StaticMethodsInterceptPoint;
import com.spark.sniffer.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import com.spark.sniffer.plugin.match.ClassMatch;
import com.spark.sniffer.plugin.match.MultiClassNameMatch;
import com.spark.sniffer.plugin.plugins.interceptor.RedisTemplateInterceptor;

import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import net.bytebuddy.matcher.ElementMatchers;

public class RedisTemplateOperationPlugin extends ClassInstanceMethodsEnhancePluginDefine {

    @Override
    protected ClassMatch enhanceClass() {
        return MultiClassNameMatch.byMultiClassMatch("org.springframework.data.redis.core.DefaultValueOperations",
            "org.springframework.data.redis.core.DefaultSetOperations",
            "org.springframework.data.redis.core.DefaultZSetOperations",
            "org.springframework.data.redis.core.DefaultListOperations",
            "org.springframework.data.redis.core.DefaultHashOperations",
            "org.springframework.data.redis.core.DefaultGeoOperations",
            "org.springframework.data.redis.core.DefaultClusterOperations",
            "org.springframework.data.redis.core.DefaultHyperLogLogOperations");
    }

    @Override
    protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
        return new InstanceMethodsInterceptPoint[] {new InstanceMethodsInterceptPoint() {
            @Override
            public ElementMatcher<MethodDescription> getMethodsMatcher() {
                return ElementMatchers.isPublic();
            }

            @Override
            public Class<?> getMethodsInterceptor() {
                return RedisTemplateInterceptor.class;
            }

            @Override
            public boolean isOverrideArgs() {
                return false;
            }
        }};
    }

    @Override
    protected StaticMethodsInterceptPoint[] getStaticMethodsInterceptPoints() {
        return null;
    }
}
